import _objectSpread from "@babel/runtime/helpers/esm/objectSpread2";
import _regeneratorRuntime from "@babel/runtime/regenerator";

/**
 * model 平台级计量单位定义
 * @date: 2018-7-6


 */
import { getResponse, createPagination } from 'utils/utils';
import { searchUomData, saveUomData as _saveUomData } from "../services/uomService";
export default {
  namespace: 'uom',
  state: {
    list: [],
    pagination: {}
  },
  effects: {
    fetchUomData: /*#__PURE__*/_regeneratorRuntime.mark(function fetchUomData(_ref, _ref2) {
      var payload, call, put, result;
      return _regeneratorRuntime.wrap(function fetchUomData$(_context) {
        while (1) {
          switch (_context.prev = _context.next) {
            case 0:
              payload = _ref.payload;
              call = _ref2.call, put = _ref2.put;
              _context.next = 4;
              return call(searchUomData, payload);

            case 4:
              result = _context.sent;
              result = getResponse(result);

              if (!result) {
                _context.next = 9;
                break;
              }

              _context.next = 9;
              return put({
                type: 'updateState',
                payload: {
                  list: result.content,
                  pagination: createPagination(result)
                }
              });

            case 9:
            case "end":
              return _context.stop();
          }
        }
      }, fetchUomData);
    }),
    // 批量保存新增计量单位
    saveUomData: /*#__PURE__*/_regeneratorRuntime.mark(function saveUomData(_ref3, _ref4) {
      var payload, call, result;
      return _regeneratorRuntime.wrap(function saveUomData$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              payload = _ref3.payload;
              call = _ref4.call;
              _context2.next = 4;
              return call(_saveUomData, payload);

            case 4:
              result = _context2.sent;
              return _context2.abrupt("return", getResponse(result));

            case 6:
            case "end":
              return _context2.stop();
          }
        }
      }, saveUomData);
    })
  },
  reducers: {
    updateState: function updateState(state, _ref5) {
      var payload = _ref5.payload;
      return _objectSpread(_objectSpread({}, state), payload);
    }
  }
};